/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bsc.ejb.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

/**
 *
 * @author Miguel Angel
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED )
public abstract class ScoreCard implements Serializable, Comparable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long idScoreCard;

    @Column(columnDefinition="text")
    private String name;
    @Column(columnDefinition="text")
    private String description;
    @Column(columnDefinition="text")
    private String responsable;
    @Column(columnDefinition="text")
    private String unit;

    @OneToMany
    private List<Note> notes;
    @OneToMany
    private List<ActionPlan> actionPlan;

    /*@ManyToMany(targetEntity=ScoreCard.class)
    @JoinTable(name="PersonScoreCard",
    joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idPerson"))
    private Collection<Person> persons;*/
    @ManyToOne
    private Person responsible;

    @ManyToMany(targetEntity=Dimension.class)
    @JoinTable(name="ScoreCardDimension",
    joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idDimension"))
    private Collection<Dimension> dimensions;

    /*@ManyToMany(targetEntity=ScoreDomain.class)
    @JoinTable(name="ScoreCardDomain",
    joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idScoreDomain"))
    private Collection<ScoreDomain> scoreDomains;*/

    @ManyToMany(targetEntity=ScoreCard.class)
    @JoinTable(name="ScoreCardRelation",
    joinColumns=@JoinColumn(name="idScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idOtherScoreCard"))
    private Collection<ScoreCard> scoreCards;

    @ManyToMany(targetEntity=ScoreCard.class)
    @JoinTable(name="ScoreCardRelation",
    joinColumns=@JoinColumn(name="idOtherScoreCard"),
    inverseJoinColumns=@JoinColumn(name="idScoreCard"))
    private Collection<ScoreCard> otherScoreCards;

    @OneToMany
    private List<Topic> topics;

    @OneToOne
    private Settings settings;

    @OneToOne
    private ScoreView scoreview;

    private Double score;
    
    @Transient
    private Long x;
    @Transient
    private Long y;

    public List<Topic> getTopics() {
        return topics;
    }

    public void setTopics(List<Topic> topics) {
        this.topics = topics;
    }

    public List<Note> getNotes() {
        return notes;
    }

    public void setNotes(List<Note> notes) {
        this.notes = notes;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Collection<Dimension> getDimensions() {
        return dimensions;
    }

    public void setDimensions(Collection<Dimension> dimensions) {
        this.dimensions = dimensions;
    }

    public Long getIdScoreCard() {
        return idScoreCard;
    }

    public void setIdScoreCard(Long idScoreCard) {
        this.idScoreCard = idScoreCard;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<ScoreCard> getOtherScoreCards() {
        return otherScoreCards;
    }

    public void setOtherScoreCards(Collection<ScoreCard> otherScoreCards) {
        this.otherScoreCards = otherScoreCards;
    }

    public Person getResponsible() {
        return responsible;
    }

    public void setResponsible(Person responsible) {
        this.responsible = responsible;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public Collection<ScoreCard> getScoreCards() {
        return scoreCards;
    }

    public void setScoreCards(Collection<ScoreCard> scoreCards) {
        this.scoreCards = scoreCards;
    }

    public Settings getSettings() {
        return settings;
    }

    public void setSettings(Settings settings) {
        this.settings = settings;
    }

    public Long getX() {
        return x;
    }

    public void setX(Long x) {
        this.x = x;
    }

    public Long getY() {
        return y;
    }

    public void setY(Long y) {
        this.y = y;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idScoreCard != null ? idScoreCard.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ScoreCard)) {
            return false;
        }
        ScoreCard other = (ScoreCard) object;
        if ((this.idScoreCard == null && other.idScoreCard != null) || (this.idScoreCard != null && !this.idScoreCard.equals(other.idScoreCard))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "bsc.ejb.entity.ScoreCard[id=" + idScoreCard + "]";
    }

    /**
     * @return the scoreview
     */
    public ScoreView getScoreview() {
        return scoreview;
    }

    /**
     * @param scoreview the scoreview to set
     */
    public void setScoreview(ScoreView scoreview) {
        this.scoreview = scoreview;
    }

    /**
     * @return the responsable
     */
    public String getResponsable() {
        return responsable;
    }

    /**
     * @param responsable the responsable to set
     */
    public void setResponsable(String responsable) {
        this.responsable = responsable;
    }

    /**
     * @return the unit
     */
    public String getUnit() {
        return unit;
    }

    /**
     * @param unit the unit to set
     */
    public void setUnit(String unit) {
        this.unit = unit;
    }


    public int compareTo(ScoreCard o) {
        return getName().compareTo(o.getName());
    }

    /**
     * @return the actionPlan
     */
    public List<ActionPlan> getActionPlan() {
        return actionPlan;
    }

    /**
     * @param actionPlan the actionPlan to set
     */
    public void setActionPlan(List<ActionPlan> actionPlan) {
        this.actionPlan = actionPlan;
    }

}
